<template>
  <div>
<h1>增加理财</h1>
<table>
  <tr>
    <td>理财名称</td>
    <td><input type="text" v-model="state.LC_Name"></td>
  </tr>
  <tr>
    <td>年收益</td>
    <td><input type="text" v-model="state.LC_ShouYi"></td>
  </tr>
  <tr>
    <td>利息</td>
    <td>
      <select v-model="state.L_Id">
        <option value="0">请选择</option>
        <option :value="item.L_Id" v-for="item in list">{{item.L_Number*100}}%</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>最低金额</td>
    <td><input type="text"  v-model="state.LC_Money"></td>
  </tr>
  <tr>
    <td>风险等级</td>
    <td>
      <select v-model="state.F_Id">
        <option value="0">请选择</option>
        <option :value="item.F_Id" v-for="item in lists">{{item.F_Name}}</option>
      </select>
    </td>
  </tr>
  <tr>
    <td></td>
    <td><input type="button" value="增加理财" @click="add"></td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs,onMounted} from 'vue'
import axios from 'axios'
import {useRoute,useRouter} from 'vue-router'
const router=useRouter()
const route=useRoute()

let data:any=reactive({
  state:{
    LC_Name:'',
    LC_ShouYi:'',
    L_Id:0,
    LC_Money:'',
    F_Id:0,
  },
  list:[],
  lists:[]
})

let {state,list,lists}=toRefs(data)

onMounted(()=>{
  getData()
  getDate()
})

const getData=()=>{
  axios({
    url:'/api/LiCai/XiaLa1',
    method:'get'
  })
  .then(res=>{
    console.log(res.data);
    list.value=res.data.data
  })
}

const getDate=()=>{
  axios({
    url:'/api/LiCai/XiaLa2',
    method:'get'
  })
  .then(res=>{
    console.log(res.data);
    lists.value=res.data.data
  })
}

const add=()=>{
  if(state.value.LC_Name==""){
    alert('理财项目不能为空');
    return;
  }
  if(Number(state.value.LC_Money)<=0){
    alert('理财项目不能小于零');
    return;
  }

  axios({
    url:'/api/LiCai/LiCaiAdd',
    method:'post',
    data:state.value
  })
  .then(res=>{
    if(res.data.data==-1){
      alert('理财名称已存在');
      return;
    }
    else{
      alert('添加理财成功');
      router.push('/licaiShow');
    }
  })
}
</script>

<style scoped>

</style>